<?php

class User_model extends CI_Model {
    
    function __construct() {
        parent::__construct();
    }
    
    function create($profil){
        $this->db->insert('userprofil', $profil);
    }
    
    function login($identifiant, $password){
        return count($this->db->select("*")
                      ->from("user")
                      ->where(array("login" => $identifiant, "password" => $password))
                      ->get()
                      ->result()) > 0 ? true : false;
    }
    
    function get_all(){
        $this->db->order_by('login', 'asc');
        $query = $this->db->get('user');
        
        if($query->num_rows() > 0){
            foreach($query->result() as $row){
                $data[] = $row;
            }
            return $data;
        }
    }
    
    function get($limit, $length){
        $this->db->order_by('login', 'asc');
        $this->db->limit($limit, $length);
        $query = $this->db->get('user');
        
        if($query->num_rows() > 0){
            foreach($query->result() as $row){
                $data[] = $row;
            }
            return $data;
        }
    }
    
    function count_all(){
        return $this->db->count_all_results('user');
    }
    
}
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
?>
